<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<form action="/common/register" method="post">
    username:<input type="text" name="username"><br><br>
    password:<input type="text" name="password"><br><br>
    retryPassword:<input type="text" name="retryPassword"><br><br>
    phone:<input type="text" name="phone"><br><br>
    smscode:<input type="text" name="smsCode"><br><br>
    imgCode:<input type="text" name="imgCode" placeholder="验证码">
    <img id="img" name="imgs" src="/common/imgCode"  width="80" height="26"/><br><br>
    <input type="submit" value="submit">
</form>
<!-- jQuery 2.2.3 -->
<script src="/js/jquery.min.js"></script>
<script>
    $(document).ready(function () {
        sendRequest();
    });
    $('#img').on('click',function(){
        $(this).attr('src','/common/imgCode?r='+Math.random());
        sendRequest();
    })
    function sendRequest() {
        $.ajax({
            url: '/common/imgCode',
            type: "GET",
            dataType: "text",
            cache: false,
            // data: $("#loginform").serialize(),
            success: function(res){
                console.log("res"+res);
                console.log("mydata" + res["message"]);
                $("#img").attr("src",res);
            },
            error:function(xhr, textStatus, errorThrown){
                console.log("ajax request error")
                /*错误信息处理*/
                console.log("进入error---");
                console.log("状态码："+xhr.status);
                console.log("状态:"+xhr.readyState);//当前状态,0-未初始化，1-正在载入，2-已经载入，3-数据进行交互，4-完成。
                console.log("错误信息:"+xhr.statusText );
                console.log("返回响应信息："+xhr.responseText );//这里是详细的信息
                console.log("请求状态："+textStatus);
                console.log(errorThrown);
                console.log("请求失败")
            }
        });
    }
</script>
</body>
</html>